﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Data;
using System.Net.Mail;
using System.Net;
using System.Text;

using Gift.DAL;


    public class login
    {
        readonly static MemberAccount theMemberAccount = new MemberAccount();
        // Methods
        public static void getpass(string usn, string memberid, string sendMode, string videcode)
        {
            DataTable table = SQLAccess.GreatDs("SELECT * FROM DB_Member where memberid=" + memberid + "").Tables[0];
            if (table.Rows.Count > 0)
            {
                string[] strArray = info.info1("", "shopemail").ToString().Split(new char[] { '@' });
                string body = "尊敬的用户您好：<br />请您点击以下链接创建帐户密码！这个链接24小时内有效";
                string str4 = body;
                string str5 = str4 + "<br />" + fun.geturl1("") + "forget2.aspx?memberid=" + memberid + "&videcode=" + videcode + "<br />如果您不能点击以上按钮，请将该链接复制到浏览器地址栏中访问，也可以完成新密码的创建！";
                body = str5 + "如有任何疑问，请访问" + info.info1("", "shopname") + "帮助中心(" + fun.geturl1("") + "news.aspx?nid=8)，或者与" + info.info1("", "shopname") + "客服取得联系。<Br />联系电话：" + info.info1("", "shoptel") + "";
                SmtpClient client = new SmtpClient();
                //{
                //    Host = "smtp." + strArray[1],
                //    UseDefaultCredentials = true,
                //    Credentials = new NetworkCredential(strArray[0], info.info1("", "shopwebmsg").ToString()),
                //    DeliveryMethod = SmtpDeliveryMethod.PickupDirectoryFromIis
                //};
                client.Host = "smtp." + strArray[1];
                //  client.Port = 25;
                client.Credentials = new System.Net.NetworkCredential(strArray[0], info.info1("", "shopwebmsg").ToString());
                MailMessage message = new MailMessage(info.info1("", "shopemail").ToString(), table.Rows[0]["email"].ToString(), "" + info.info1("", "shopname") + "：请继续创建帐户密码", body);
                //{
                //    BodyEncoding = Encoding.GetEncoding("gb2312"),
                //    SubjectEncoding = Encoding.GetEncoding("gb2312"),
                //    IsBodyHtml = false,
                //    Priority = MailPriority.Normal
                //};

                try
                {

                    client.Send(message);
                    SQLAccess.DoSql("update  DB_Member set videcode='" + videcode + "' where memberid=" + table.Rows[0]["memberid"].ToString() + "");

                }
                catch (Exception ex)
                {
                }
                HttpContext.Current.Response.Write("<script>location.href='forget1.aspx';</script>");
            }
        }

        public static bool lo(string usn, string pwd)
        {
            DataTable table = SQLAccess.GreatDs("SELECT AdminId,AdminFlag FROM tbAdminlogin where AdminUser='" + usn + "' and AdminPwd='" + pwd + "'").Tables[0];
            if (table.Rows.Count > 0)
            {
                SQLAccess.DoSql(string.Concat(new object[] { "update tbAdminlogin set logindegree=logindegree+1,loginip='", HttpContext.Current.Request.UserHostAddress, "',logintime='", DateTime.Now, "' where AdminUser='", usn, "' and AdminPwd='", pwd, "'" }));
                return true;

            }
            else
            {
                return false;
            }
        }

    

        void SendEmail(string sTo, string sFrom, string sBody)
        {
            string to = "abc@sina.com";
            string from = "mathieuxiao@yahoo.com.cn";
            string subject = "Using the new SMTP client.";
            string body = @"Using this new feature, you can send an e-mail message from an application very easily.";
            MailMessage message = new MailMessage(from, to, subject, body);
            // SmtpClient client = new SmtpClient("smtp.sina.com.cn");   
            SmtpClient client = new SmtpClient();
            client.Host = "202.108.3.190";
            client.Port = 25;

            client.Credentials = new System.Net.NetworkCredential("abc@sina.com", "123456");
            try
            {
                client.Send(message);
            }
            catch (Exception ex)
            {

            }

        }

    }
